<?php


namespace app\model\user;


use think\Model;
use think\model\concern\SoftDelete;

class UserModel extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $name = 'user';
    protected $autoWriteTimestamp = true;

    protected $hidden = ['password', 'update_time', 'delete_time'];


    public function setPasswordAttr($value)
    {
        if (!$value) {
            return '';
        }
        return password_hash($value, PASSWORD_DEFAULT);
    }

    public function inviteUser()
    {
        return $this->hasOne(UserModel::class, 'id', 'pid')->bind(['invite_name' => 'username']);
    }
}